#include "Result.h"
#include "SnakeWorld.h"
#include "Choose.h"
#include "Menu.h"
using namespace cocos2d;

CCScene* Result::scene()
{
	CCScene *scene = NULL;
	do
	{
		scene = CCScene::create();
		CC_BREAK_IF(!scene);
		Result *layer = Result::create();
		CC_BREAK_IF(!layer);
		scene->addChild(layer);
	} while (0);
	return scene;
}

bool Result::init()
{
	bool bRet = false;
	do
	{
		CC_BREAK_IF(!CCLayer::init());

		

		CCSize size = CCDirector::sharedDirector()->getWinSize();

		//CCLabelTTF *pOver = CCLabelTTF::create("Game Over","Arial",40);
		//CC_BREAK_IF(!pOver);
		//pOver->setPosition(ccp(size.width/2,size.height/2 + 50));
		//this->addChild(pOver,2);

		CCSprite * mu = CCSprite::create("gameover.jpg");
		CC_BREAK_IF(!mu);
		mu->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height/2));
		this->addChild(mu,0);

		CCLabelTTF *pStart = CCLabelTTF::create("RESET","Segoe Marker",24);
		CC_BREAK_IF(!pStart);

		CCLabelTTF *pClose = CCLabelTTF::create("MENU","Segoe Marker",24);
		CC_BREAK_IF(!pClose);

		CCMenuItemLabel *pStartItem = CCMenuItemLabel::create(pStart,this,menu_selector(Result::resetGame));
		CC_BREAK_IF(!pStartItem);
		pStartItem->setPosition(ccp(size.width/2 + 60,size.height/2));

		CCMenuItemLabel *pCloseItem = CCMenuItemLabel::create(pClose,this,menu_selector(Result::backMenu));
		CC_BREAK_IF(!pCloseItem);
		pCloseItem->setPosition(ccp(size.width/2 + 60,size.height/2 - 40));

		CCMenu *menu = CCMenu::create(pStartItem,pCloseItem,NULL);
		menu->setPosition(CCPointZero);
		CC_BREAK_IF(!menu);
		this->addChild(menu,1);

		//CCActionInterval *actTo = CCBlink::create(10,10);
		//pOver->runAction(actTo);

		bRet = true;
	} while (0);
	return bRet;
}

void Result::resetGame(CCObject* p)
{
	CCScene *s = Choose::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,s));
}

void Result::backMenu(CCObject* p)
{
	CCScene *s = Menu::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,s));
}


void Result::menuCloseCallBack(CCObject* pSender)
{
	CCDirector::sharedDirector()->end();
}
